package com.feisuanyz.lyweb01.controller;

import com.feisuanyz.lyweb01.constant.ResultCodeConstant;
import com.feisuanyz.lyweb01.pojo.domain.ProductDO;
import com.feisuanyz.lyweb01.pojo.dto.CreateGroup;
import com.feisuanyz.lyweb01.pojo.dto.DeleteGroup;
import com.feisuanyz.lyweb01.pojo.dto.ProductDTO;
import com.feisuanyz.lyweb01.pojo.dto.RestResult;
import com.feisuanyz.lyweb01.pojo.dto.UpdateGroup;
import com.feisuanyz.lyweb01.pojo.query.ProductQuery;
import com.feisuanyz.lyweb01.pojo.query.QueryGroup;
import com.feisuanyz.lyweb01.pojo.vo.PageResult;
import com.feisuanyz.lyweb01.service.ProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 产品中心
 *
 * @author deng
 * @date 2025-02-26 11:57:37
 */
@Tag(name = "产品中心")
@RequestMapping("product")
@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 获取产品列表
     *
     * @param productQuery 产品查询对象
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @Operation(summary = "获取产品列表")
    public RestResult<PageResult<ProductDO>> productList(@Validated(QueryGroup.class) ProductQuery productQuery) {
        PageResult<ProductDO> result = productService.productList(productQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取产品详情
     *
     * @param productQuery 产品查询对象
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @Operation(summary = "获取产品详情")
    public RestResult<ProductDO> productInfo(@Validated(QueryGroup.class) ProductQuery productQuery) {
        ProductDO result = productService.productInfo(productQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 搜索产品
     *
     * @param productQuery 产品查询对象
     * @return
     */
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @Operation(summary = "搜索产品")
    public RestResult<List<ProductDO>> searchProduct(@Validated(QueryGroup.class) ProductQuery productQuery) {
        List<ProductDO> result = productService.searchProduct(productQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 添加产品
     *
     * @param productDTO 产品信息对象
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Operation(summary = "添加产品")
    @ResponseBody
    public RestResult<Boolean> addProduct(@RequestBody @Validated(CreateGroup.class) ProductDTO productDTO) {
        Boolean result = productService.addProduct(productDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 修改产品
     *
     * @param productDTO 产品信息对象
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @Operation(summary = "修改产品")
    public RestResult<Boolean> updateProduct(@Validated(UpdateGroup.class) ProductDTO productDTO) {
        Boolean result = productService.updateProduct(productDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除产品
     *
     * @param productDTO 产品信息对象
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @Operation(summary = "删除产品")
    public RestResult<Boolean> deleteProduct(@Validated(DeleteGroup.class) ProductDTO productDTO) {
        Boolean result = productService.deleteProduct(productDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}
